package com.godaiyu.lagou.algorithm;

import java.util.HashSet;
import java.util.Set;

/**
 * @author godai
 * @date 2021/8/2 23:09
 * @description
 */
public class RepeatedCheck {

    public static void main(String[] args) {
        System.out.println(RepeatedCheck.isRepeated(new int[]{1, 2, 3}));
        System.out.println(RepeatedCheck.isRepeated(new int[]{1, 2, 3, 7, 3, 6}));
        System.out.println(RepeatedCheck.isRepeated(new int[]{1, 2, 1}));
    }

    public static boolean isRepeated(int[] arr) {
        if (arr == null || arr.length < 2) {
            return false;
        }

        Set<Integer> sets = new HashSet<Integer>();
        for (Integer item : arr) {
            if (!sets.add(item)) {
                return true;
            }
        }

        return false;
    }
}
